home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.04 Apr 88 / TearOffPalette Source / Dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-10  |  3.1 KB  |  118 lines  |  [TEXT/KAHL]

  1. /*
  2. ----------------------------------------------------------------------------------------------------
  3. T E A R O F F   P A L E T T E
  4.  
  5.     version 1.0
  6.     by Don Melton and Mike Ritter
  7.     
  8.     Copyright (C)1987, 1988 by Impulse Technologies, Inc., all rights reserved. 
  9.     
  10.     Filename:            Dialog.c
  11.     Font:                    Monaco, 9 point
  12.     Tab setting:    2
  13.     Compiler:            LightspeedC 2.15, Project type: APPL, Creator: TOPD
  14.     Segment:            Main */
  15.  
  16.  
  17.  
  18. /*
  19. ----------------------------------------------------------------------------------------------------
  20. GLOBAL CONSTANT DEFINITIONS AND VARIABLE DECLARATIONS */
  21.  
  22. #include "Constants.h"
  23. #include "Variables.h"
  24.  
  25. /*
  26. ----------------------------------------------------------------------------------------------------
  27. EXTERNAL FUNCTION DECLARATIONS */
  28.  
  29. extern short GoodResource();                                /* Error.c */
  30. extern short GetMenuBarHeight();                        /* Interface.c */
  31.  
  32. /*
  33. ----------------------------------------------------------------------------------------------------
  34. FORWARD FUNCTION DECLARATIONS */
  35.  
  36. void DoAbout();
  37. short PositionDialog();
  38. pascal Boolean DialogFilter();
  39.  
  40.  
  41.  
  42. /*
  43. ----------------------------------------------------------------------------------------------------
  44. DO ABOUT */
  45.  
  46. void DoAbout() {
  47.     DialogRecord theDialogRecord;
  48.     short itemHit;
  49.     
  50.     if(PositionDialog(ABOUT_DIALOG_ID)) {
  51.         (void) GetNewDialog(ABOUT_DIALOG_ID, &theDialogRecord, BRING_TO_FRONT);
  52.         ShowWindow(&theDialogRecord);
  53.         
  54.         do {
  55.             ModalDialog(DialogFilter, &itemHit);
  56.         }
  57.         while(itemHit == 0);
  58.         
  59.         CloseDialog(&theDialogRecord);
  60.     }
  61. }
  62.  
  63. /*
  64. ----------------------------------------------------------------------------------------------------
  65. POSITION DIALOG
  66.  
  67.     PositionDialog() centers a DITL resource horizontally and positions it one-third down the screen
  68.     vertically. */
  69.  
  70. short PositionDialog(whichID)
  71. short whichID;
  72. {
  73.     DialogTHndl theTemplate;
  74.     
  75.     if(!GoodResource(theTemplate = (DialogTHndl) GetResource('DLOG', whichID))) {
  76.         return(false);
  77.     }
  78.     OffsetRect(&(*theTemplate)->boundsRect,
  79.             - (*theTemplate)->boundsRect.left
  80.                     + ((screenBits.bounds.right - screenBits.bounds.left)
  81.                     - ((*theTemplate)->boundsRect.right - (*theTemplate)->boundsRect.left))
  82.                     / 2,
  83.             - (*theTemplate)->boundsRect.top
  84.                     + (((screenBits.bounds.bottom - screenBits.bounds.top - GetMenuBarHeight())
  85.                     - ((*theTemplate)->boundsRect.bottom - (*theTemplate)->boundsRect.top))
  86.                     / 3)
  87.                     + GetMenuBarHeight());
  88.     return(true);
  89. }
  90.  
  91. /*
  92. ----------------------------------------------------------------------------------------------------
  93. DIALOG FILTER
  94.  
  95.     DialogFilter() allows exit of ModalDialog() on any mouseDown or keyDown event. */
  96.  
  97. pascal Boolean DialogFilter(whichDialog, whichEvent, whichItem)
  98. DialogPtr whichDialog;
  99. EventRecord *whichEvent;
  100. short *whichItem;
  101. {
  102.     WindowPtr whichWindow;
  103.     
  104.     if((whichEvent->what == mouseDown) || (whichEvent->what == keyDown)) {
  105.     
  106.         if((FindWindow(whichEvent->where, &whichWindow) == inMenuBar)
  107.                 || ((whichEvent->what == keyDown) && (whichEvent->modifiers & cmdKey))) {
  108.             /* Re-post the event and ignore the error, if any. */
  109.             (void) PostEvent(whichEvent->what, whichEvent->message);
  110.         }
  111.         *whichItem = 1;
  112.         return(true);
  113.     }
  114.     else {
  115.         return(false);
  116.     }
  117. }
  118.